let filterTableItemKeys = [21, 22, 23, 24, 25, 28, 29, 30, 31]
let arrData = {
    "员工编号": "80030618",
    "员工姓名": "周慧",
    "全路径机构": "内蒙古电力公司,乌兰察布供电分公司,专业生产机构,修试管理处,综合（党群）管理室,主任（兼业务工作）",
    "年份": "2025",
    "月份": "07",
    "1日": "",
    "1日_1": "",
    "2日": "",
    "2日_1": "",
    "3日": "",
    "3日_1": "",
    "4日": "",
    "4日_1": "",
    "5日": "",
    "5日_1": "",
    "6日": "",
    "6日_1": "",
    "7日": "",
    "7日_1": "",
    "8日": "",
    "8日_1": "",
    "9日": "",
    "9日_1": "",
    "10日": "",
    "10日_1": "",
    "11日": "",
    "11日_1": "",
    "12日": "",
    "12日_1": "",
    "13日": "",
    "13日_1": "",
    "14日": "",
    "14日_1": "",
    "15日": "",
    "15日_1": "",
    "16日": "",
    "16日_1": "",
    "17日": "",
    "17日_1": "",
    "18日": "",
    "18日_1": "",
    "19日": "",
    "19日_1": "",
    "20日": "",
    "20日_1": "",
    "21日": "年休假",
    "21日_1": "",
    "22日": "年休假",
    "22日_1": "",
    "23日": "年休假",
    "23日_1": "",
    "24日": "年休假",
    "24日_1": "",
    "25日": "年休假",
    "25日_1": "",
    "26日": "",
    "26日_1": "",
    "27日": "",
    "27日_1": "",
    "28日": "年休假",
    "28日_1": "",
    "29日": "年休假",
    "29日_1": "",
    "30日": "年休假",
    "30日_1": "",
    "31日": "年休假",
    "31日_1": ""
}

let arrObj = {}, arrObjPre = {dayKey: '', dayNum: '', dayOffType: '', dayOffFlag: ''}

const getDayOffType = (arrItemValue) => {
    return arrItemValue.includes("/") ? arrItemValue.split("/")[0] : arrItemValue
}

const getDayOffFlag = (arrItemValue) => {
    return arrItemValue.includes("/") ? arrItemValue.split("/")[1] : ""
}

filterTableItemKeys.forEach(item => {
    let betweenDayOffTypeSame = getDayOffType(arrData[`${item}日`]) === arrObjPre.dayOffType
    let betweenDayOffFlagRight = getDayOffFlag(arrData[`${item}日`]) !== '下午' && arrObjPre.dayOffFlag !== '上午'
    if (Object.keys(arrObj).length === 0) {
        arrObj[item] = [item]
        arrObjPre.dayKey = item
    } else if (item === arrObjPre.dayNum + 1 && betweenDayOffTypeSame && betweenDayOffFlagRight) {
        let arrObjPreList = arrObj[arrObjPre.dayKey] ? arrObj[arrObjPre.dayKey] : []
        arrObj[arrObjPre.dayKey] = [...arrObjPreList, item]
    } else {
        arrObj[item] = [item]
        arrObjPre.dayKey = item
    }
    arrObjPre.dayNum = item
    arrObjPre.dayOffType = getDayOffType(arrData[`${item}日`])
    arrObjPre.dayOffFlag = getDayOffFlag(arrData[`${item}日`])
    console.log("arrObj", arrObj)
})

// console.log(arrObj) //{ '17': [ 17 ], '18': [ 18 ], '30': [ 30, 31 ] }

const getDayOffNum = (dayList) => {
    return dayList.map(dayItem => arrData[`${dayItem}日`].includes("/") ? 0.5 : 1).reduce((total, value) => total + value)
}
//type:1 开始，2:结束
const getDayOffTime = (dayList, type) => {
    if (type === 1) return arrData[`${dayList[0]}日`].includes("下午") ? `${dayList[0]} 14:30:00` : `${dayList[0]} 8:30:00`
    if (type === 2) return arrData[`${dayList[dayList.length - 1]}日`].includes("上午") ? `${dayList[dayList.length - 1]} 12:00:00` : `${dayList[dayList.length - 1]} 18:00:00`
}

Object.entries(arrObj).forEach(([key, value]) => {
    arrObj[key] = {
        '请假天数': getDayOffNum(value),
        '开始时间': getDayOffTime(value, 1),
        '结束时间': getDayOffTime(value, 2)
    }
})
// arrObj {
//   '17': { '请假天数': 0.5, '开始时间': '17 8:30:00', '结束时间': '17 12:00:00' },
//   '18': { '请假天数': 1, '开始时间': '18 8:30:00', '结束时间': '18 18:00:00' },
//   '30': { '请假天数': 1.5, '开始时间': '30 14:30:00', '结束时间': '31 18:00:00' }
// }
console.log("arrObj", arrObj)
